
import { useScreenStore, useSlidesStore } from '@/store'
import { enterFullscreen, exitFullscreen, isFullscreen } from '@/utils/fullscreen'

export default () => {
  const screenStore = useScreenStore()
  const slidesStore = useSlidesStore()

  // 进入放映状态（从当前页开始）
  const enterScreening = async () => {


    enterFullscreen()
    screenStore.setScreening(true)

    // var src = screenStore.screenyulan.slice(screenStore.accect)


    // for (var i = 0; i < src.length; i++) {
    //   await new Promise(function (res, req) {
    //     setTimeout(function () {
    //       if (i != src.length - 1) {
    //         screenStore.setScreening(false)
    //       } else {
    //         slidesStore.updateSlideIndex(src[i].id + 1)
    //       }
    //       res(src[i].id)

    //     }, src[i].timer * 1000)
    //   })
    // }
    // src.reduce(function(con,pre){

    // })

    //  await   screenStore.screenyulan.slice(screenStore.accect).forEach( a=>{
    //  setTimeout(function(){
    //   console.log(a);

    // },1000)
    //     })


  }

  // 进入放映状态（从第一页开始）
  const enterScreeningFromStart = () => {
    slidesStore.updateSlideIndex(0)
    enterScreening()
  }

  // 退出放映状态
  const exitScreening = () => {

    screenStore.setScreening(false)
    if (isFullscreen()) exitFullscreen()
  }

  return {
    enterScreening,
    enterScreeningFromStart,
    exitScreening,
  }
}